import { ReactComponentPage } from "../../class/ReactComponentPage";
import { HashRouter as AppRouter, Switch, Route } from "react-router-dom";
import React from "react";
import { ConfigProvider } from "antd";
import zhCN from "antd/es/locale/zh_CN";
import { WelcomePage } from "../WelcomePage/WelcomePage";
import { BookListPage } from "../BookListPage/BookListPage";
import { ListPage } from "../ListPage/ListPage";
import { OpArticlesPage } from "../OpArticlesPage/OpArticlesPage";
import {RdArticlesPage} from "../RdArticlesPage/RdArticlesPage";
import {ContentPage} from "../ContentPage/ContentPage";
import { createHashHistory, History } from "history";
export namespace App {
    export interface Props extends ReactComponentPage.Props {
    }

    export interface State extends ReactComponentPage.State {
        history: History<any>;
    }
}

export class App extends ReactComponentPage {
    public readonly state: App.State = {
        history: createHashHistory(),
    };
    public render() {
        return (
            <ConfigProvider locale={zhCN}>
                <AppRouter>
                    <Switch>
                        <Route exact path="/">
                            <WelcomePage></WelcomePage>
                        </Route>
                        <Route path="/read/books">
                            <BookListPage></BookListPage>
                        </Route>
                        <Route path="/operate/books">
                            <ListPage></ListPage>
                        </Route>
                        <Route path="/operate/articles/:bookId" component={OpArticlesPage}/>
                        <Route path="/read/articles/:bookId" component={RdArticlesPage} />
                        <Route path="/read/article/:articleId" component={ContentPage} />
                    </Switch>
                </AppRouter>
            </ConfigProvider>
        );
    }
    public componentDidMount(): void {
        this.state.history.listen(() => {
            console.log("-- force update ---");
            this.forceUpdate();
        });
    }
}
